#lang racket

(require "primitives.rkt")

;Closes a tunnel. Call the destructor.
(define (tunnel-close tunn)
  ((tunnel-_destructor tunn)))

(define (tunnel-speed tunn)
  (define toret
    (/ (unbox (tunnel-_bytesbox tunn))
       (- (current-inexact-milliseconds)
          (unbox (tunnel-_lasttimebox tunn)))))
  (set-box! (tunnel-_lasttimebox tunn) (current-inexact-milliseconds))
  (set-box! (tunnel-_totbytesbox tunn) (+ (unbox (tunnel-_totbytesbox tunn)) (unbox (tunnel-_bytesbox tunn))))
  (set-box! (tunnel-_bytesbox tunn) 0)
  (/ (round (* 1000 toret)) 1000.0))

(provide (all-defined-out))